<?php
use Workerman\Worker;
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__.'/auth.php';
//worker 对象
$http_worker = new Worker("http://0.0.0.0:2304");
//路由及中间件对象
$router = new AdminRouter();
//加载控制器
$controller =  scandir(__DIR__.'/controller/');
foreach ($controller as $v){
    if(in_array($v,['.','..'])){
        continue;
    }
    require_once __DIR__.'/controller/'.$v;
}
// 启动进程数
$http_worker->count = 10;
$http_worker->name  = "admin_name";
//初始化
$http_worker->onWorkerStart = function(){
    require_once __DIR__.'/../public_config.php';
    require_once __DIR__.'/../redis.php';
    require_once __DIR__.'/../db.php';
    require_once __DIR__.'/tools.php';
    require_once __DIR__."/../Singleton.php";
    require_once __DIR__."/../ApiError.php";
    require_once __DIR__."/../Req.php";
    require_once __DIR__."/../jwt.php";
    //ApiError::setProduct(true);//正式环境开启
    date_default_timezone_set('PRC');
    //自动加载
    spl_autoload_register(function ($class){
        require_once __DIR__.'/'.$class.'.php';
    },false);
    \think\facade\Db::setConfig([
        'default' => "mysql",
        'connections' => [
            'mysql' => MYSQL,
        ],
    ]);
};


$http_worker->onMessage = [$router,"onClientMessage"];
Worker::$logFile = './logs/workerman_admin.log';
Worker::$stdoutFile = './logs/admin.log';
// 运行worker
Worker::runAll();